package server

import (
	"fmt"
	"time"

	pb "lht-go-plugins/internal/server/proto"
)

// GEO 异步处理
func (s *PluginServiceImpl) handleGeoAsync(stream pb.PluginService_HandleRequestStreamServer, req *pb.CommonRequest) {
	fmt.Printf("[ASYNC][GEO] 异步处理开始: %s\n", req.RequestId)
	time.Sleep(2 * time.Second)

	resp := &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "GEO 异步任务完成",
	}
	if err := stream.Send(resp); err != nil {
		fmt.Printf("[ASYNC][GEO] 发送失败: %v\n", err)
	}
}

// 算法异步
func (s *PluginServiceImpl) handleAlgorithmAsync(stream pb.PluginService_HandleRequestStreamServer, req *pb.CommonRequest) {
	fmt.Printf("[ASYNC][ALGORITHM] 执行算法任务: %s\n", req.RequestId)
	time.Sleep(3 * time.Second)

	resp := &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "算法异步执行完成",
	}
	_ = stream.Send(resp)
}

// 加解密异步
func (s *PluginServiceImpl) handleEncryptAsync(stream pb.PluginService_HandleRequestStreamServer, req *pb.CommonRequest) {
	fmt.Printf("[ASYNC][ENCRYPTION] 加解密开始: %s\n", req.RequestId)
	time.Sleep(1 * time.Second)

	resp := &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "加解密异步完成",
	}
	_ = stream.Send(resp)
}

// 缓存异步
func (s *PluginServiceImpl) handleCacheAsync(stream pb.PluginService_HandleRequestStreamServer, req *pb.CommonRequest) {
	fmt.Printf("[ASYNC][CACHE] 缓存异步执行: %s\n", req.RequestId)
	time.Sleep(1 * time.Second)

	resp := &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "缓存异步任务完成",
	}
	_ = stream.Send(resp)
}

// 数据库异步
func (s *PluginServiceImpl) handleDatabaseAsync(stream pb.PluginService_HandleRequestStreamServer, req *pb.CommonRequest) {
	fmt.Printf("[ASYNC][DATABASE] 数据库异步操作: %s\n", req.RequestId)
	time.Sleep(2 * time.Second)

	resp := &pb.CommonResponse{
		RequestId: req.RequestId,
		Code:      0,
		Message:   "数据库异步操作完成",
	}
	_ = stream.Send(resp)
}
